package com.hengtongxing.hejiayun.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hengtongxing.hejiayun.R;
import com.hengtongxing.hejiayun.bean.GoodsListBean;
import com.hengtongxing.hejiayun.utils.GlideUtils;
import com.hengtongxing.hejiayun.utils.NumberFormatUtils;
import com.hengtongxing.hejiayun.widget.RoundImageView;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 消息列表
 */
public class ImgListAdapter extends RecyclerView.Adapter<ImgListAdapter.ViewHolder> {

    private List<String> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;

    public void setOnCallBackListener(onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }

    public ImgListAdapter(List<String> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_img_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String s = listsBeans.get(position);
        GlideUtils.loadImage(context, holder.ivPicture,s);
        holder.itemView.setOnClickListener(v -> {
            onCallBackListener.onCallBack(position);
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_picture)
        RoundImageView ivPicture;


        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int position);
    }
}
